package cn.tedu.jewelry.mapper;

import cn.tedu.jewelry.entity.Product;
import cn.tedu.jewelry.entity.User;
import cn.tedu.jewelry.entity.UserAddress;
import cn.tedu.jewelry.entity.Order;
import cn.tedu.jewelry.vo.UserAddressStandVO;
import cn.tedu.jewelry.vo.UserStandVO;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

//用户模块
@Mapper
public interface UserMapper {

    //用户搜索:根据用户名搜索
    @Select("select * from user where username=#{username}")
    UserStandVO getUserByUserName(String username);

    //用户列表
    @Result(column = "gmt_created", property = "gmtCreated")
    @Select("select * from user")
    List<UserStandVO> getUserList();

    //用户登录
    @Select("select password from user where username=#{username}")
    User login(String username);

    //添加用户
    @Insert("insert into user values(#{username},#{password},#{nick},#{phone},#{tel},#{email},#{created},#{credits},#{status})")
    void reg1(User user);

    //用户地址管理:获取所有用户地址
    @Select("select * from useraddress")
    List<UserAddressStandVO> getUserAddressList();

    //用户地址:按用户名查询地址
    @Result(column = "user_id", property = "userId")
    @Result(column = "contact_name", property = "contactName")
    @Select("select * from useraddress where contact_name=#{contactName}")
    List<UserAddressStandVO> getUserAddressByContactName(String contactName);

    @Result(column = "user_id", property = "userId")
    @Result(column = "contact_name", property = "contactName")
    @Select("select * from useraddress where user_id=#{userId}")
    List<UserAddressStandVO> getUserAddressByUserId(Long userId);

    //修改用户启用状态
    @Update("update user set enable=#{enable} where id=#{id}")
    void updateUserByIdAndEnable(Long id,Integer enable);
}
